import {
    Form,
    Input,
    Button,
    Radio,
    Select,
    Cascader,
    DatePicker,
    InputNumber,
    TreeSelect,
    Switch,
    Checkbox,
    Upload,
} from 'antd';

import { generateUID } from "../../utils/index"

export const selOp = (option = []) => {
    return option.map(el => {
        return (<Select.Option value={el.value} key={generateUID()}>{el.name}</Select.Option>)
    })
}

export class useFormFunc {
    constructor(org) { }

    createInput(item, $props) {
        switch (item.type) {
            case 'input':
                return (
                    <Input onChange={value => $props?.change(value, item.name, item)} style={{ width: '220px' }} allowClear />
                )
            case 'select':
                return (
                    <Select onChange={value => $props?.change(value, item.name, item)} style={{ width: '220px' }} allowClear>
                        {selOp(item?.option)}
                    </Select>
                )
            case 'number':
                return (
                    <InputNumber onChange={value => $props?.change(value, item.name, item)} style={{ width: '220px' }} allowClear />
                )
            case 'textArea':
                return (
                    <Input.TextArea showCount maxLength={item.maxLength} style={{ width: '220px' }} />
                )
            case 'date':
                return (
                    <DatePicker style={{ width: '220px' }} />
                )
            /**
             * 其他类型input在此扩展
             */
            default:
                return null
        }
    }
}

